package cn.lingyangwl.agile.system.model.entity;

import cn.lingyangwl.agile.tenant.core.DataIsolation;
import cn.lingyangwl.agile.model.BasePO;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * 租户用户信息
 */
@TableName("sys_tenant_user")
@Getter
@Setter
@Accessors(chain = true)
@DataIsolation(filterTenant = true, tableName = "sys_tenant_user")
public class SysTenantUser extends BasePO implements Serializable {

    private static final long serialVersionUID = 1L;

    public static LambdaQueryWrapper<SysTenantUser> lqw() {
        return Wrappers.lambdaQuery();
    }

    public static LambdaUpdateWrapper<SysTenantUser> luw() {
        return Wrappers.lambdaUpdate();
    }

    /**
     * 编码
     */
    @TableId
    private Long id;

    /**
     * 关联的用户id
     */
    private Long userId;

    /**
     * 关联的租户id
     */
    private String tenantId;

    /**
     * 租户场景id
     */
    private Long sceneId;

    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date createdAt;

    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date lastLoginTime;

    @TableField(exist = false)
    private SysUser user;
}
